import Vue from 'vue'
import Router from 'vue-router'
import Layout from '../layout/index'

Vue.use(Router)

export const constantRouterMap = [
  { path: '/login',
    meta: { title: '登录', noCache: true },
    component: (resolve) => require(['@/views/login'], resolve),
    hidden: true
  },
  {
    path: '/404',
    component: (resolve) => require(['@/views/features/404'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: (resolve) => require(['@/views/features/401'], resolve),
    hidden: true
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: (resolve) => require(['@/views/features/redirect'], resolve)
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        component: (resolve) => require(['@/views/home'], resolve),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'index', affix: true, noCache: true }
      },
      {
        path: 'sales',
        component: (resolve) => require(['@/views/retail/sales/index'], resolve),
        name: 'sales',
        meta: {
          title: '门店进货'
        }
      },
      {
        path: 'products',
        component: (resolve) => require(['@/views/retail/products/index'], resolve),
        name: 'products',
        meta: { title: '门店销货' }
      },
      {
        path: 'purchaseLog',
        component: (resolve) => require(['@/views/retail/purchaseLog/index'], resolve),
        name: 'purchaseLog',
        meta: { title: '门店进货日志' }
      },
      {
        path: 'salesLog',
        component: (resolve) => require(['@/views/retail/salesLog/index'], resolve),
        name: 'salesLog',
        meta: { title: '门店销货日志' }
      },
      {
        path: 'chargeLog',
        component: (resolve) => require(['@/views/retail/chargeLog/index'], resolve),
        name: 'chargeLog',
        meta: { title: '门店服务费日志' }
      },
      {
        path: 'stockorder',
        component: (resolve) => require(['@/views/retail/stockorder/index'], resolve),
        name: 'stockorder',
        meta: { title: '进货订单' }
      },
      {
        path: 'salesorder',
        component: (resolve) => require(['@/views/retail/salesorder/index'], resolve),
        name: 'salesorder',
        meta: { title: '销货订单' }
      },
      {
        path: 'recharge',
        component: (resolve) => require(['@/views/retail/recharge/index'], resolve),
        name: 'recharge',
        meta: { title: '门店充值中心权限' }
      },
      {
        path: 'stock',
        component: (resolve) => require(['@/views/retail/products/form'], resolve),
        name: 'stock',
        meta: { title: '选择商品' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'center',
        component: (resolve) => require(['@/views/system/user/center'], resolve),
        name: '个人中心',
        meta: { title: '个人中心' }
      }
    ]
  },
  {
    path: '/yshop/materia/index',
    name: `images`,
    meta: {
      title: '上传图片',
      noCache: true
    },
    component: (resolve) => require(['@/components/editorMaterial/index'], resolve),
    hidden: true
  }
]

// const createRouter = () => new Router({
//   // mode: 'history', // require service support
//   scrollBehavior: () => ({ y: 0 }),
//   routes: constantRouterMap
// })

// const router = createRouter()

// // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// export function resetRouter() {
//   const newRouter = createRouter()
//   router.matcher = newRouter.matcher // reset router
// }

export default new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
